#ifndef _BATTLE_SCENE_H_
#define _BATTLE_SCENE_H_

#include "render_target.h"
#include "player.h"
#include "dude.h"
#include "dude_controller.h"
#include <vector>
#include <memory>

class BattleScene : public RenderTarget, public DudeController
{
protected:
	RenderTarget *bgNode, *fgNode;
	double offset, targetOffset;
	bool rightDangerZone, leftDangerZone;
	bool PositionNewDude(Dude* dude);
	bool findSpotInRow(Dude* dude, std::vector<std::unique_ptr<Dude>> *row, int &spot);
public:
	//std::vector<Dude*> allDudes;
	//std::vector<Dude*> leftDudes, rightDudes; //Separate lists for each team, pointing to the same dudes in allDudes

	//Left and right Paths are a vector of vectors. The top level vector is the row on the field. The bottom level is the dude in the row.
	std::vector<std::vector<std::unique_ptr<Dude>>> leftPaths, rightPaths;

	Player *leftPlayer, *rightPlayer;
	void RemoveDude(Dude* dude);
	bool AddDude(Dude* dude); //Takes a dude and initializes appareance, places on screen
	BattleScene(std::string id);
	~BattleScene();
	void SetArena(std::string resourceName, std::string resourceName2);
	void Update(double timeDelta);
	void Heartbeat();

	std::vector<std::vector<std::unique_ptr<Dude>>>* GetPathsForSide(PlayerSide side);
	std::vector<std::unique_ptr<Dude>>* GetRowForDude(Dude* dude);
	int GetDudeCountForSide(PlayerSide side);

	bool AtFront(Dude *dude); //am I the front of my row right now?
	Dude* GetEnemy(Dude *dude); //Get enemy if any of this dude
	Dude* GetNextDude(Dude *dude); //Get dude in front of this dude
	double GetMiddleBoundary(); //Get the X of the middle boundary
	bool TryMoveSideways(Dude *dude);
	int FindDudeInRow(Dude *dude, std::vector<std::unique_ptr<Dude>> &row);
};

#endif